AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

ENT.WireDebugName = "Radio Receiver"

local MODEL = Model("models/radio/ra_cell_tower1.mdl")

function ENT:Initialize()
	self.Entity:SetModel( MODEL )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:StartMotionController()

	self.Inputs = Wire_CreateInputs(self.Entity, { "Active", "Frequency", "Secure Code [STRING]" })
	self.Outptus = Wire_CreateOutputs(self.Entity, { "Active", "Frequency", "Secure", "Data [ARRAY]" })
	
	self.On = false
	self.Secure = ""
	self.Freq = 720
	self.Data = {}
end

function ENT:Setup(m)
	MODEL = Model(m)
end

function ENT:Output()
	
end

function ENT:TriggerInput(name, val)
	if name == "Active" then
		self.On = (val > 0)
	elseif name == "Frequency" then
		self.Freq = math.Clamp(val,720,1600)
	elseif name == "Secure Code" then
		self.Secure = val
	end
end

function ENT:Think()
	if self.On then
		local data = {}
		for k,v in pairs(self.Data) do
			if ValidEntity(k) then
				table.Add(data,v)
			end
		end
		Wire_TriggerOutput(self.Entity, "Data", data)
	else
		Wire_TriggerOutput(self.Entity, "Data", {})
	end
	Wire_TriggerOutput(self.Entity, "Active", self.On and 1 or 0)
	Wire_TriggerOutput(self.Entity, "Frequency", self.Freq)
	Wire_TriggerOutput(self.Entity, "Secure", self.Secure != "" and 1 or 0)
	self:NextThink(CurTime()+0.1)
end

function ENT:ShowOutput()
	
end

function ENT:TriggerOutput(out)
    
end
